package DataStructure.GenericLearning.Demo2;

import java.util.ArrayList;

/**
 *  测试 泛型的通配
 */
public class Test {
    public static void main(String[] args) {

        //ArrayList<F> f = new ArrayList<>();
        //ArrayList<S2> s1 = new ArrayList<>();
        //f = s1; // 错误，泛型不允许协变

        ArrayList<String> list1 = new ArrayList<>();
        ArrayList<Object> list2 = new ArrayList<>();

        // ? extends E
        // 向下限定，E及其子类
        //ArrayList<F> f = new ArrayList<>();
        //ArrayList<S1> s1 = new ArrayList<>();
        //ArrayList<? extends F> list;
        //list = s1;
        // //错误，list2里面存储的是非A及其子类型
        //list = list2;

        // ? super E
        // 向上限定，E及其父类
        //ArrayList<F> f = new ArrayList<>();
        //ArrayList<S1> s1 = new ArrayList<>();
        //ArrayList<? super F> list;
        //list = f;
        //list = list2;
        //list = s1;
        //ArrayList<? super A> list = ss; // 错误，S1是A的子类


    }
}

class F {}

class S1 extends F {}

class S2 extends F {}
